<extend name="Layout/ins_popup" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	<div class="popup-frame">
		<div class="popup-header">
			<div class="pull-left">
				<h1>修改密码</h1>
			</div>
			<div class="pull-right">
				<a id="btn_save" class="btn" >确定</a>
				<a id="btn_close" class="btn btn-cancel">关闭</a>
			</div>
		</div>
		<div class="popup-body">
			<div class="popup-body-scroll">
				<div class="popup-content">
					<form id="form_data" name="form_data" method="post" >
						<input type="hidden" name="user_id" id="user_id">
						<div class="layui-form-item">
							<label class="layui-form-label" >新密码：</label>
							<div class="layui-input-block">
								<input type="password" name="password" id="password" value=""  class="layui-input col-20">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" >确认密码：</label>
							<div class="layui-input-block">
								<input type="password" name="confirm_password" id="confirm_password" value=""  class="layui-input col-20"/>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" ></label>
							<div class="layui-input-block">
								<p class="layui-input-static">
									<span id="msg" ></span>
								</p>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		var index = parent.layer.getFrameIndex(window.name);
		layui.use('global', function() {
			var $ = layui.jquery;
			var user_id = '';
			$("#form_user input[name='user_id[]']:checked", parent.document).each(function() {
				user_id += this.value + ',';
			});

			$("#user_id").val(user_id);

			$("#password").keydown(function() {
				s = $(this).val();
				t = check_password(s);
				if (t == 0) {
					$("#msg").html("密码过短");
					$("#msg").css("color", "red");
				}
				if (t == 1) {
					$("#msg").html("密码强度差");
					$("#msg").css("color", "red");
				}
				if (t == 2) {
					$("#msg").html("密码强度良好");
					$("#msg").css("color", "blue");
				}
				if (t == 3) {
					$("#msg").html("密码强度高");
					$("#msg").css("color", "blue");
				}
			});

			$("#confirm_password").keyup(function() {
				new_pwd = $("#password").val();
				confirm_pwd = $(this).val();
				if (new_pwd != confirm_pwd) {
					$("#msg").html("密码不一致");
					$("#msg").css("color", "red");
				} else {
					$("#msg").html("密码一致");
					$("#msg").css("color", "blue");
					$("#status").val("true");
				}
			});

			$("#btn_save").on('click', function() {
				var msg = "";
				new_pwd = $("#password").val();
				confirm_pwd = $("#confirm_password").val();
				if (new_pwd == confirm_pwd) {
					var vars = $("#form_data").serialize();
					send_ajax("{:U('reset_pwd')}", vars, function(data) {
						layer.msg(data.info, {
							time : 1200
						}, function() {
							parent.layer.close(index);
						});
					});
				} else {
					layer.msg("密码不一致");
				}
			});

			//关闭iframe
			$('#btn_close').click(function() {
				parent.layer.close(index);
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:U('winpop')}", 560, 470);
			});
		});
	</script>
</block>